package cn.kai.org.service.impl;

import cn.kai.basic.util.MyMailUtil;
import cn.kai.org.domain.Shop;
import cn.kai.org.domain.ShopAuditLog;
import cn.kai.org.mapper.ShopMapper;
import cn.kai.org.service.IShopAuditLogService;
import cn.kai.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kai
 * @since 2022-06-14
 */
@Service
public class ShopAuditLogServiceImpl extends BaseServiceImpl<ShopAuditLog> implements IShopAuditLogService {
    @Autowired
    private JavaMailSender javaMailSender;

    @Autowired
    private ShopMapper shopMapper;

    /**
     * 审核通过
     * @param shopAuditLog
     */
    @Override
    @Transactional
    public void pass(ShopAuditLog shopAuditLog) {
        //设置店铺日志对应状态数据，用于记录哪个人员修改的哪个店铺，修改成哪个状态
        shopAuditLog.setState(2);
        //设置当前操作人员id
        shopAuditLog.setAuditId(334L);
        //调用父类方法，保存数据
        super.save(shopAuditLog);
        //修改对应店铺的状态
        Shop shop = shopMapper.loadById(shopAuditLog.getShopId());
        shop.setState(2);
        shopMapper.update(shop);

        //发送激活邮件
        String sendMail = "1246979270@qq.com";
        String subject = "宠物乐园店铺入驻激活";
        String contentText = "恭喜你通过审核,请点击连接链接激活 http://localhost:8080/shop/activation/"+shopAuditLog.getShopId();
        String acceptMail = "1246979270@qq.com";
//        MyMailUtil.simpleMail(javaMailSender,sendMail,subject,contentText,acceptMail);
    }

    /**
     * 驳回店铺
     * @param shopAuditLog
     */
    @Override
    @Transactional
    public void reject(ShopAuditLog shopAuditLog) {
        shopAuditLog.setState(-1);
        shopAuditLog.setAuditId(334L);
        super.save(shopAuditLog);

        Shop shop = shopMapper.loadById(shopAuditLog.getShopId());
        shop.setState(-1);
        shopMapper.update(shop);
    }
}
